package com.example.web.controller;

import com.example.common.response.R;
import com.example.system.domain.Bo.FriendBo;
import com.example.system.domain.Bo.PageBo;
import com.example.system.domain.Vo.FriendVo;
import com.example.system.domain.Vo.PageVo;
import com.example.system.service.FriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(value = "好友管理", tags = {"好友管理"})
@RequestMapping(value = "/friend", method = {RequestMethod.POST, RequestMethod.GET})
public class FriendController {

    @Autowired
    private FriendService friendService;

    @ResponseBody
    @RequestMapping("/getList")
    @ApiOperation("获取当前用户的好友列表")
    public R<PageVo<FriendVo>> getList(@RequestBody PageBo pageBo) {
        PageVo<FriendVo> vo = friendService.getListPage(pageBo);
        return R.ok(vo);
    }

    @ResponseBody
    @RequestMapping("/getList/search/{username}")
    @ApiOperation("搜索当前用户的某一个好友")
    public R<PageVo<FriendVo>> getListSearch(@PathVariable("username") String username, @RequestBody PageBo pageBo) {
        PageVo<FriendVo> vo = friendService.getListSearch(username, pageBo);
        return R.ok(vo);
    }

    @ResponseBody
    @RequestMapping("/searchAll/{username}")
    @ApiOperation("搜索-支持模糊查询")
    public R<List<FriendVo>> searchAll(@PathVariable("username") String username) {
        List<FriendVo> vo = friendService.searchAll(username);
        return R.ok(vo);
    }

    @ResponseBody
    @RequestMapping("/getList/application")
    @ApiOperation("当前用户的申请列表")
    public R<PageVo<FriendVo>> getListApplication(@RequestBody PageBo pageBo) {
        PageVo<FriendVo> vo = friendService.getListApplication(pageBo);
        return R.ok(vo);
    }

    @ResponseBody
    @RequestMapping("/getList/applicationLog")
    @ApiOperation("当前用户发起的申请记录")
    public R<PageVo<FriendVo>> getListApplicationLog(@RequestBody PageBo pageBo) {
        PageVo<FriendVo> vo = friendService.getListApplicationLog(pageBo);
        return R.ok(vo);
    }

    @ResponseBody
    @RequestMapping("/change/status")
    @ApiOperation("改变好友关系")
    public R<String> changeStatus(@RequestBody FriendBo bo) {
        return friendService.changeStatus(bo);
    }

}
